package com.zhubjiept.app.jinrirong.activity.user.presenter;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.zhubjiept.app.common.base.BasePresenter;
import com.zhubjiept.app.jinrirong.activity.user.view.RankingView;
import com.zhubjiept.app.jinrirong.config.Constants;
import com.zhubjiept.app.jinrirong.config.RetrofitHelper;

import io.reactivex.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;


/**
 * Created by Yangli on 2018/4/19.
 */

public class MyInfoPresenter extends BasePresenter<RankingView> {
    private String headImgUrl;

    public String getHeadImgUrl() {
        return headImgUrl;
    }

    public void setHeadImgUrl(String headImgUrl) {
        this.headImgUrl = headImgUrl;
    }

    public void requestIncomingRankingInfo(String token) {
        mView.showLoadingView();
        JSONObject requestData = new JSONObject();
        try {
            requestData.put("client", Constants.CLIENT);
            requestData.put("package", Constants.PACKAGE);
            requestData.put("ver", Constants.VER);
            requestData.put("token", token);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), requestData.toString());
        addTask(RetrofitHelper.getInstance().getService().incomingRanking(requestBody), new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("请求佣金排行榜 返回：" + s);
                mView.hideLoadingView();
                JSONObject result = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(s);
                getView().onRemoteSucceed(result);
            }
        });
    }


    public void requestProductRankingInfo(String token) {
        mView.showLoadingView();
        JSONObject requestData = new JSONObject();
        try {
            requestData.put("client", Constants.CLIENT);
            requestData.put("package", Constants.PACKAGE);
            requestData.put("ver", Constants.VER);
            requestData.put("token", token);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), requestData.toString());
        addTask(RetrofitHelper.getInstance().getService().productRanking(requestBody), new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("请求产品排行榜 返回：" + s);
                mView.hideLoadingView();
                JSONObject result = (com.alibaba.fastjson.JSONObject) com.alibaba.fastjson.JSONObject.parse(s);
                getView().onRemoteSucceed(result);
            }
        });
    }
}
